package pta;/**
 * @author： li
 * @date： 2022-03-31 21:25
 * @version 1.0
 */
import java.util.*;
public class 一帮一 {
    static class stu{
        private int x;
        private boolean rank;
        private String name;

        public stu(int x, boolean rank, String name) {
            this.x = x;
            this.rank = rank;
            this.name = name;
        }

        public void setRank(boolean rank) {
            this.rank = rank;
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Vector<stu> help = new Vector<>();
        int n = sc.nextInt();
        for(int i=1;i<=n;i++){
            help.add(new stu(sc.nextInt(),true,sc.next()));
        }
        System.out.println(help.get(4).name+" "+help.get(4).x+" "+help.get(4).rank);
        int l=0,r=help.size()-1;
        while (!help.isEmpty()){
            if(help.size()==2){
                    System.out.println(help.get(l).name + " " + help.get(r).name);
                break;
            }
            else if(help.get(l).x!=help.get(r).x&&help.get(r).rank) {
                        System.out.println(help.get(l).name + " " + help.get(r).name);
                        help.get(r).setRank(false);
                        help.remove(r);
                        help.remove(l);
                        r=help.size()-1;
                    }
                    else
                        r--;


        }
    }
}
